﻿using BLL;
using EncryptHelper;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;

namespace Loginter.ajax
{
    /// <summary>
    /// TruckTeamAdd 的摘要说明
    /// </summary>
    public class TruckTeamAdd : IHttpHandler,IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //车队名称
           string name= context.Request.Form["Name"];
            //负责人
            string leader = context.Request.Form["Leader"];
            //备注
            string remark = context.Request.Form["Remark"];
            //当前的时间
            string time = DateTime.Now.ToShortDateString();
            TruckTeamBLL team = new TruckTeamBLL();
            //调用MODEL层的车队信息
            TruckTeamMODEL tt = new TruckTeamMODEL()
            {
                //车队名称
                TeamName = name,
                //车队负责人
                Leader = leader,
                //备注
                Remark = remark,
                //添加的当前时间
                CheckInTime = Convert.ToDateTime(time),
                //修改的当前的时间
                AlterTime = Convert.ToDateTime(time)
            };
            //定义一个int类型接收BLL层的车队信息
            int result = team.UInsertTruckTeam(tt);
            JavaScriptSerializer js = new JavaScriptSerializer();
            //判断信息是否为0，不为0添加成功，否则添加失败
            if (result == 1)
            {
                context.Session["TruckTeamInfo"] = tt.TeamID;
                //context.Response.Write("yes");
                OperateResult usert = new OperateResult(1, "添加成功");
                string json = js.Serialize(usert);
                context.Response.Write(json);
            }
            else
            {
                OperateResult usert = new OperateResult(-1, "添加失败");
                string json = js.Serialize(usert);
                context.Response.Write(json);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}